package net.qiqb.dao.mybatis.plus.event;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDateTime;

public class DomainEventLogDaoImpl extends ServiceImpl<DomainEventLogPOMapper, DomainEventLogPO> implements DomainEventLogDao {

    @Override
    public boolean savePO(DomainEventLogPO domainEventLogPO) {
        return super.save(domainEventLogPO);
    }

    @Override
    public DomainEventLogPO getByEventIdAndServiceName(String eventId, String serviceName,String listenerId) {
        QueryWrapper<DomainEventLogPO> queryWrapper = new QueryWrapper<>();
        // 查等待下发的领域事件
        queryWrapper.lambda()
                .eq(DomainEventLogPO::getEventId, eventId)
                .eq(DomainEventLogPO::getProcessServiceName, serviceName)
                .eq(DomainEventLogPO::getListenerId,listenerId)
        ;
        return super.getOne(queryWrapper);
    }

    @Override
    public boolean updateResultById(String id, LocalDateTime finishProcessTime, Long processInterval, String processResult, String note) {
        UpdateWrapper<DomainEventLogPO> updateWrapper = new UpdateWrapper<>();
        // 查等待下发的领域事件
        updateWrapper.lambda()
                .eq(DomainEventLogPO::getId, id)
                .set(DomainEventLogPO::getFinishProcessTime, finishProcessTime)
                .set(DomainEventLogPO::getProcessInterval, processInterval)
                .set(DomainEventLogPO::getProcessResult, processResult)
                .set(DomainEventLogPO::getNotes, note)
        ;
        return super.update(updateWrapper);
    }
}
